package org.xiaog.fastdao.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author xiaog
 */
public class SaveUtil {

    private SaveUtil() {}

    public static int save(String sql,Object[] params) {
        Connection connection = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        int result = 0;
        try {
            connection = DataSourceUtil.getConnection();
            pst = connection.prepareStatement(sql);
            for (int i = 0; i < params.length; i++) {
                pst.setObject(i+1,params[i]);
            }
            result = pst.executeUpdate();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DataSourceUtil.closeResource(connection,pst,rs);
        }
        return result;
    }

}
